<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>关闭 MySQL 连接</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysql-close" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysql_close</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_close</span> &mdash; <span class="dc-title">关闭 MySQL 连接</span></p>

 </div>

 <div id="function.mysql-close-refsynopsisdiv">
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="para">本扩展自 PHP 5.5.0
起已废弃，并在自 PHP 7.0.0 开始被移除。应使用 <a href="book.mysqli.html" class="link">MySQLi</a>
或 <a href="ref.pdo_mysql.html" class="link">PDO_MySQL</a> 扩展来替换之。参见
<a href="mysqlinfo.api.choosing.html" class="link">MySQL：选择 API</a> 指南以及<a href="faq.databases.html#faq.databases.mysql.deprecated" class="link">相关 FAQ</a> 来获取更多信息。用以替代本函数的有：</p>
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mysqli.close.html" class="function">mysqli_close()</a></span></li>
    <li class="member">PDO: 为 PDO 对象设置一个 <strong><code>NULL</code></strong> 值 </li>
   </ul>
  </div>
 </div>
 
 <div class="refsect1 description" id="refsect1-function.mysql-close-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mysql_close</strong></span>
    ([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code><span class="initializer"> = NULL</span></span>
  ] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mysql_close()</strong></span> 关闭指定的连接标识所关联的到
   MySQL 服务器的非持久连接。如果没有指定
   <code class="parameter">link_identifier</code>，则关闭上一个打开的连接。
  </p>
  <p class="para">
   通常不需要使用
   <span class="function"><strong>mysql_close()</strong></span>，因为已打开的非持久连接会在脚本执行完毕后自动关闭。参见<a href="language.types.resource.html#language.types.resource.self-destruct" class="link">释放资源</a>。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-close-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    <dt>
<code class="parameter">
link_identifier</code></dt>
<dd>
<p class="para"> MySQL 连接. 如果该连接标识符未给出, 将使用最近一次<span class="function"><a href="mysql_connect.html" class="function">mysql_connect()</a></span>建立的连接. 
如果没有找到可使用的连接, 将产生一个 <strong><code>E_WARNING</code></strong> 错误.</p></dd>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-close-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysql-close-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2119">
    <p><strong>Example #1 <span class="function"><strong>mysql_close()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_user'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'mysql_password'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Could&nbsp;not&nbsp;connect:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br />}<br />echo&nbsp;</span><span style="color: #DD0000">'Connected&nbsp;successfully'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">mysql_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Connected successfully
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-close-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="function"><strong>mysql_close()</strong></span> 不会关闭由
    <span class="function"><a href="mysql_pconnect.html" class="function">mysql_pconnect()</a></span> 建立的持久连接。
   </p>
  </p></blockquote>
 </div>


  <div class="refsect1 seealso" id="refsect1-function.mysql-close-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mysql_connect.html" class="function" rel="rdfs-seeAlso">mysql_connect()</a> - 打开一个到 MySQL 服务器的连接</span></li>
    <li class="member"><span class="function"><a href="mysql_free_result.html" class="function" rel="rdfs-seeAlso">mysql_free_result()</a> - 释放结果内存</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>